﻿using EDesk.apis.camera;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EDesk.apis
{
    /// <summary>
    /// JS引用入口主对象：EDesk
    /// Web端引用方法：EDeskReady().then(() => {
    ///     EDesk.xxx();
    /// });
    /// 注：各API对象都可通过主对象进行访问，无需再进行JS注入。
    /// </summary>
    class JsApi
    {

        //摄像头窗体
        private CameraForm cameraForm;

        public string Hello()
        {
            return "hello!";
        }

        public CameraResult Camera()
        {
            return CameraEvent(false, null, null, null);
        }

        public CameraResult CameraSave(string picFilePath, string picFileName, string picFileExt)
        {
            return CameraEvent(true, picFilePath, picFileName, picFileExt);
        }

        private CameraResult CameraEvent(bool saveDisk, string picFilePath, string picFileName, string picFileExt)
        {
            if (cameraForm == null) cameraForm = new CameraForm();
            cameraForm.SaveDisk = saveDisk;
            if (saveDisk)
            {
                cameraForm.PicFilePath = picFilePath;
                cameraForm.PicFileName = picFileName;
                cameraForm.PicFileExt = picFileExt;
            }
            DialogResult ret = cameraForm.ShowDialog(MainForm.ins);
            if (ret == DialogResult.OK)
            {
                return cameraForm.result;
            }
            return null;
        }

    }
}
